using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameTime : MonoBehaviour
{
    public Text timerText;
    private float timer = 0f;
    private bool isRunning = false;
    // Start is called before the first frame update
    void Start()
    {
        timer = 0f;
        isRunning = true;   
    }

    // Update is called once per frame
    void Update()
    {
        if (isRunning)
        {
            timer += UnityEngine.Time.deltaTime;
            UpdateTimerText();
        }
    }
    void UpdateTimerText()
    {
        int minutes = (int)(timer / 60);
        int seconds = (int)(timer % 60);
        int milliseconds = (int)((timer - (int)timer) * 100);
        timerText.text = string.Format("{0:00}:{1:00}.{2:00}", minutes, seconds, milliseconds);
    }
    public void PauseTimer()
    {
        isRunning = false;
    }
    public void StartTimer()
    {
        isRunning = true;
    }
    public void ResetTimer()
    {
        timer = 0f;
        UpdateTimerText();
    }
}
